package com.caifeng.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Animal> mData;
    //    private Context mContext;
    private AnimalAdapter mAdapter;
    private ListView list_animal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init();
//        mContext = MainActivity.this;


    }

    private void init() {
        list_animal = (ListView) findViewById(R.id.list_animal);
        mAdapter = new AnimalAdapter(getToData(), this);
        list_animal.setAdapter(mAdapter);
    }

    private List<Animal> getToData() {
        mData = new ArrayList<>();
//        mList = new ArrayList<>();
        Animal animal = new Animal();//Animal里需要构造器

        animal.setaName("a");
        animal.setaSpeak("bbb");
        animal.setaIcon(R.mipmap.ic_launcher_round);
        mData.add(animal);

        animal = new Animal();
        animal.setaName("a");
        animal.setaSpeak("bbb");
        animal.setaIcon(R.mipmap.ic_launcher_round);
        mData.add(animal);

        animal = new Animal();
        animal.setaName("a");
        animal.setaSpeak("bbb");
        animal.setaIcon(R.mipmap.ic_launcher_round);
        mData.add(animal);

        animal = new Animal();
        animal.setaName("a");
        animal.setaSpeak("bbb");
        animal.setaIcon(R.mipmap.ic_launcher_round);
        mData.add(animal);

        animal = new Animal();
        animal.setaName("cc");
        animal.setaSpeak("hhhh");
        animal.setaIcon(R.mipmap.ic_launcher_round);
        mData.add(animal);


        return mData;

    }

}
